package cn.tedu.eshihui.service.impl;

import cn.tedu.eshihui.mapper.UserMapper;
import cn.tedu.eshihui.pojo.dto.UserRegDto;
import cn.tedu.eshihui.pojo.entity.User;
import cn.tedu.eshihui.pojo.vo.UserStandardVO;
import cn.tedu.eshihui.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper mapper;
    @Override
    public void addUser(UserRegDto userRegDto) {
        log.debug("开始处理添加用户业务");
        UserStandardVO userVO = mapper.selectByUsername(userRegDto.getUsername());
        if (userVO != null) {
            String message = "该用户已存在";
            log.warn(message);
            throw new SecurityException(message);
        }
        User u = new User();
        BeanUtils.copyProperties(userRegDto, u);
        mapper.insert(u);
    }







}